class Member:
    """会员类，包含会员等级和折扣率"""
    def __init__(self, level):
        self.level = level  # 会员等级

    @property
    def discount_rate(self):
        """根据会员等级计算折扣率"""
        if self.level == "普通会员":
            return 0.95  # 95折
        elif self.level == "银卡会员":
            return 0.90  # 9折
        elif self.level == "金卡会员":
            return 0.85  # 85折
        elif self.level == "钻石会员":
            return 0.80  # 8折
        else:
            return 1.00  # 默认无折扣

    def __str__(self):
        return f"{self.level}，折扣率：{self.discount_rate:.0%}"


class CartItem:
    """购物车中的商品项"""
    def __init__(self, name, price, quantity, member=None):
        self.name = name  # 商品名称
        self.price = price  # 商品单价
        self.quantity = quantity  # 商品数量
        self.member = member  # 会员对象

    def total_price(self):
        """计算商品小计"""
        return self.price * self.quantity

    def discounted_price(self):
        """计算折扣后的商品价格"""
        if self.member:
            return self.total_price() * self.member.discount_rate
        else:
            return self.total_price()

    def __str__(self):
        return f"{self.name} x{self.quantity}，单价：{self.price:.2f}，小计：{self.total_price():.2f}"


class ShoppingCart:
    """购物车类"""
    def __init__(self):
        self.items = []  # 购物车中的商品项列表

    def add_item(self, item):
        """添加商品到购物车"""
        self.items.append(item)

    def apply_discount(self):
        """计算折扣后的总价"""
        total_discounted_price = sum(item.discounted_price() for item in self.items)
        return total_discounted_price

    def show(self):
        """显示购物车信息，包括商品明细、折扣信息和总价"""
        print("购物车商品明细：")
        for item in self.items:
            print(item)
            if item.member:
                print(f"会员折扣：{item.member.discount_rate:.0%}")
            print(f"折扣后小计：{item.discounted_price():.2f}")
        print(f"折扣后总价：{self.apply_discount():.2f}")

# 测试代码
if __name__ == "__main__":
    # 创建会员对象
    member = Member("金卡会员")
    print(member)

    # 创建购物车对象
    cart = ShoppingCart()

    # 添加商品到购物车
    cart.add_item(CartItem("苹果", 10.0, 3, member))
    cart.add_item(CartItem("牛奶", 5.0, 2, member))
    cart.add_item(CartItem("面包", 8.0, 1))  # 无会员折扣

    # 显示购物车信息
    cart.show()